package org.soarsky.wealthchengdu.entity;

import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.soarsky.wealthchengdu.tools.Tools;

import android.util.Log;


/**
 * 公共的请求消息
 *单例模式
 */
public class PublicRequest {
	private String api;
	private String key;
	private String devId;
	private String version;
	private String format;
	private String sig;
	private String ts;
	//除登录不传其他的都要传
	private String sessionKey;
	private static PublicRequest publicRequest;
	public static PublicRequest newPublicRequest(){
		if(publicRequest==null)
			publicRequest = new PublicRequest();
		return publicRequest;
	}
	private PublicRequest(){
		key="A3Yds5Rq";
		devId="a24fg35C222A2425";
		version="1";
		format="json"; 
		ts=System.currentTimeMillis()+"";
		Log.e("ts", ts.toString());
		sig=Tools.md5((Tools.md5(devId+ts))+key);
	}
	/*
	 * 设置全局属性
	 * */
	public void setAttribute(List<NameValuePair> list){
		ts=System.currentTimeMillis()+"";
//		String fl=Tools.md5(key+ devId);
//		sig=Tools.md5(fl+ts);
		sig=Tools.md5((Tools.md5(devId+ts))+key);
		list.add(new BasicNameValuePair("api", api));
		list.add(new BasicNameValuePair("key", key));
		list.add(new BasicNameValuePair("devId", devId));
		list.add(new BasicNameValuePair("version", version));
		list.add(new BasicNameValuePair("format", format));
		list.add(new BasicNameValuePair("sig", sig));
		list.add(new BasicNameValuePair("ts", ts));
		if(sessionKey!=null){
			list.add(new BasicNameValuePair("sessionKey", sessionKey));
		}
		Log.e("list", list.toString());
	}
	public String getApi() {
		return api;
	}
	public void setApi(String api) {
		this.api = api;
	}
	public String getKey() {
		return key;
	}
	public void setKey(String key) {
		this.key = key;
	}
	public String getDevId() {
		return devId;
	}
	public void setDevId(String devId) {
		this.devId = devId;
	}
	public String getVersion() {
		return version;
	}
	public void setVersion(String version) {
		this.version = version;
	}
	public String getFormat() {
		return format;
	}
	public void setFormat(String format) {
		this.format = format;
	}
	public String getSig() {
		return sig;
	}
	public void setSig(String sig) {
		this.sig = sig;
	}
	public String getTs() {
		return ts;
	}
	public void setTs(String ts) {
		this.ts = ts;
	}
	public String getSessionKey() {
		return sessionKey;
	}
	public void setSessionKey(String sessionKey) {
		this.sessionKey = sessionKey;
	}
	
}
